import {
	inject,
	observer
} from 'mobx-react';
import {
	toJS
} from 'mobx';
import {
	WeaRadioGroup
} from 'ecCom';

@inject('commonStore')
@observer
export default class RadioGroup extends React.Component {
	constructor(props) {
		super(props);
	}

	componentDidMount() {
		this.props.commonStore.getRadioGroupConfig();
	}

	handleRadioGroupChange = (params) => {
		this.props.commonStore.exportActiveParams(params);
	}

	render() {
		const {
			radioGroup,
			setRef,
		} = this.props.commonStore, {
			config
		} = radioGroup;

		return (
			config.length > 0 && <WeaRadioGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaRadioGroup@vd0ovj`} config={toJS(config)} ref={ref => setRef(ref,'radioGroup')} onChange={params => this.handleRadioGroupChange(params)}/>
		)
	}
}